﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Storage.aspx.cs" Inherits="Web.User.Storage.Storage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../../Scripts/WebInner.js" type="text/javascript"></script>
    <script src="../../Scripts/Common.js" type="text/javascript"></script>
    <link href="../../Styles/Common.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/Zebra/zebra_dialog.js" type="text/javascript"></script>
    <link href="../../Scripts/Zebra/zebra_dialog.css" rel="stylesheet" type="text/css" />
    <script src="../../Lodop6.198/LodopFuncs.js" type="text/javascript"></script>
      <script type="text/javascript">
          /*--------窗体启动设置和基本设置--------*/
          /*--loadFuntion--*/
          $(function () {


              //初始化存储产品类型信息
              InitVarietyID();

              $('select[name=VarietyID]').change(function () { InitTypeID(); });
              $('select[name=TypeID]').change(function () { InitTimeID(); });
              $('select[name=TimeID]').change(function () { GetSotorageInfo(); });


              //初始化榜单编号
              InitWeighNO();
              //初始化存储时间

              var now = new Date(); //获取系统日期，即Sat Jul 29 08:24:48 UTC+0800 2006 
              var yy = now.getFullYear(); //截取年，即2006 
              var mo = now.getMonth() + 1; //截取月，即07 
              var dd = now.getDate(); //截取日，即29 
              //取时间 
              var hh = now.getHours(); //截取小时，即8 
              var mm = now.getMinutes(); //截取分钟，即34 
              var ss = now.getSeconds(); //获取秒 
              $('input[name=StorageDate]').val(yy + '-' + mo + '-' + dd + ' ' + hh + ':' + mm + ':' + ss);

          });

          //过磅单号
          function InitWeighNO() {
              $.ajax({
                  url: '/User/Storage/storage.ashx?type=GetWeighNO',
                  type: 'post',
                  data: '',
                  dataType: 'text',
                  success: function (r) {
                      $('input[name=WeighNO]').val(r);
                  }, error: function (r) {

                      $.Zebra_Dialog('<strong>加载储户信息失败 ！</strong>');

                  }
              });
          }

          /*--ENd loadFuntion--*/
          //获取储存产品类型
          function InitVarietyID() {
              $('select[name=VarietyID]').empty();
              $.ajax({
                  url: '/User/Storage/storage.ashx?type=GetVarietyFromStorageRate',
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {

                      for (var i = 0; i < r.length; i++) {
                          $('select[name=VarietyID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                      }
                      InitVarietyUnit();
                      InitTypeID(); //加载储户类型
                  }, error: function (r) {
                      if (r.responseText != 'Error') {
                          $.Zebra_Dialog('<strong>加载储户产品类型失败 ！</strong>');
                      }
                      if (r.responseText != 'Price') {
                          $.Zebra_Dialog('<strong>无法获取当前的存储产品和价格利率 ！</strong>');
                      }
                  }
              });
          }

          //获取存储产品的价格单位
          function InitVarietyUnit() {
              var VarietyID = $('select[name=VarietyID] option:selected').val();
              $.ajax({
                  url: '/User/Storage/storage.ashx?type=GetStorageVarietyUnitByID&VarietyID=' + VarietyID,
                  type: 'post',
                  data: '',
                  dataType: 'text',
                  success: function (r) {
                      $('#spanPrice_ShiChang').html('元/' + r);
                     
                      $('#spanStorageNumber').html(r);
                  }, error: function (r) {

                  }
              });
          }

          //获取储户类型
          function InitTypeID() {
              var VarietyID = $('select[name=VarietyID] option:selected').val();
              $('select[name=TypeID]').empty();
              $.ajax({
                  url: '/User/Storage/storage.ashx?type=GetUserTypeByVarietyID&VarietyID=' + VarietyID,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      for (var i = 0; i < r.length; i++) {
                          $('select[name=TypeID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                      }
                      InitTimeID(); //获取存期信息
                  }, error: function (r) {
                      if (r.responseText != 'Error') {
                          $.Zebra_Dialog('<strong>不存在此储户类型,您可以请管理员添加相关的基础数据信息 ！</strong>');
                      }
                  }
              });
          }

          //获取存期信息
          function InitTimeID() {
              var VarietyID = $('select[name=VarietyID] option:selected').val();
              var TypeID = $('select[name=TypeID] option:selected').val();
              $('select[name=TimeID]').empty();
              $.ajax({
                  url: '/User/Storage/storage.ashx?type=GetTimeByVUID&VarietyID=' + VarietyID + '&TypeID=' + TypeID,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      for (var i = 0; i < r.length; i++) {
                          $('select[name=TimeID]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                      }
                      GetSotorageInfo();//加载存期与价格利率
                  }, error: function (r) {
                      if (r.responseText != 'Error') {
                          $.Zebra_Dialog('<strong>加载储户存期失败 ！</strong>');
                      }
                  }
              });
          }

          //获取价格利率信息
          function GetSotorageInfo() {
              var VarietyID = $('select[name=VarietyID] option:selected').val();
              var TypeID = $('select[name=TypeID] option:selected').val();
              var TimeID = $('select[name=TimeID] option:selected').val();
              $.ajax({
                  url: '/User/Storage/storage.ashx?type=GetSotorageByVUTID&VarietyID=' + VarietyID + '&TypeID=' + TypeID + '&TimeID=' + TimeID,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                     
                      $('input[name=StorageRateID]').val(r[0].ID);
                      $('input[name=Price_ShiChang]').val(r[0].Price_ShiChang);
                      $('input[name=StorageFee]').val(r[0].StorageFee);

                      var VatietyID = $('select[name=VarietyID] option:selected').text();
                      var TypeID = $('select[name=TypeID] option:selected').text();
                      var TimeID = $('select[name=TimeID] option:selected').text();
                      var Price_ShiChang = $('input[name=Price_ShiChang]').val();
                    ShowOptionInfo();//获取当前选项信息
                  }, error: function (r) {
                      if (r.responseText != 'Error') {
                          $.Zebra_Dialog('<strong>加载储户信息失败 ！</strong>');
                      }
                  }
              });
          }

          //获取当前的存储选项信息
          function ShowOptionInfo() { 
           var VarietyID = $('select[name=VarietyID] option:selected').val();
              var TypeID = $('select[name=TypeID] option:selected').val();
              var TimeID = $('select[name=TimeID] option:selected').val();
              $.ajax({
                  url: '/User/Storage/storage.ashx?type=ShowOptionInfo&VarietyID=' + VarietyID + '&TypeID=' + TypeID + '&TimeID=' + TimeID,
                  type: 'post',
                  data: '',
                  dataType: 'text',
                  success: function (r) {
                      $('#divMsg').html('');
                      $('#divMsg').append(r);
                  }, error: function (r) {
                      $('#divMsg').html('');
                  }
              });
          }




          /*--------数据增删改操作--------*/
          //加载新的业务编号
          function InitBusinessNO() {
              $.ajax({
                  url: "/User/Storage/storage.ashx?type=GetNewBusinessNO&AccountNumber=" + $('#D_AccountNumber').html(),
                  type: 'post',
                  data: '',
                  dataType: 'text',
                  success: function (r) {
                      $('input[name=BusinessNO]').val(r);
                    
                      frmSubmit();
                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载信息失败 ！</strong>');
                  }
              });
          }



          //新增数据方法
          function frmSubmit() {
              if (!SubmitCheck()) {//检测输入内容
                  return false;
              }

              $.Zebra_Dialog('<strong>您确认已经仔细检查输入信息，并继续操作吗？</strong>', {
                  'type': 'question',
                  'title': '提示',
                  'buttons': ['Yes', 'No'],
                  'onClose': function (caption) {
                      if (caption == 'Yes') {

                          $.ajax({
                              url: '/User/Storage/storage.ashx?type=Add_Dep_Storage&AccountNumber=' + $('#D_AccountNumber').html(),
                              type: 'post',
                              data: $('#form1').serialize(),
                              dataType: 'txt',
                              success: function (r) {
                                  if (r == "OK") {
                                      // $.Zebra_Dialog('<strong>添加数据成功 ！</strong>');
                                      alert("添加数据成功，请打印单据");
                                      $('#btnAdd').attr('disabled', 'disabled');
                                      $('#btnAdd').css('background','#aaa');
                                      $('#btnCunZhe').removeAttr('disabled');
                                  } else if (r == "1") {
                                      $.Zebra_Dialog('<strong>已存在相同的类型名称，请修改后添加 ！</strong>');
                                  }
                              }, error: function (r) {
                                  $.Zebra_Dialog('<strong>添加数据失败 ！</strong>');
                              }
                          });

                      }
                      else if (caption == "No") {
                      }
                  }
              });

          }

          //提交检测
          function SubmitCheck() {
              
              var AccountNumber = $('#D_AccountNumber').html()
              if (AccountNumber == ''||AccountNumber==undefined) {
                  $.Zebra_Dialog('<strong>请先选择储户账号！</strong>');
                  $('#QAccountNumber').focus();
                  return false;
              }
              if ($('select[name=VarietyID] option:selected').val() == "") {
                  $.Zebra_Dialog('<strong>存储产品类型不能为空 ！</strong>');
                  return false;
              }
              if ($('select[name=TypeID] option:selected').val() == "") {
                  $.Zebra_Dialog('<strong>储户类型不能为空 ！</strong>');
                  return false;
              }
              if ($('select[name=TimeID] option:selected').val() == "") {
                  $.Zebra_Dialog('<strong>存期类型不能为空 ！</strong>');
                  return false;
              }
//              if (!CheckNumInt($('input[name=StorageNumber]').val(),'存储数量',1,-1)) {
//                  return false;
              //              }
              if (!CheckNumDecimal($('input[name=StorageNumber]').val(), '存储数量',2)) {
                  return false;
              }

              return true;
          }


          function FunCheckNumber() {
              if (!CheckNumDecimal($('input[name=StorageNumber]').val(), '存储数量', 2)) {
                  return false;
              }
          }

          /*--------End 数据增删改操作--------*/
       

          var p_left = 0; var p_ltop = 0; var p_lwidth = 0; var p_lheight = 0;
          $(function () {
              $.ajax({
                  url: '/Ashx/wbinfo.ashx?type=GetPrintSetting_Dep',
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      p_lwidth = r[0].Width;
                      p_lheight = r[0].Height;
                      p_lleft = r[0].DriftRateX;
                      p_ltop = r[0].DriftRateY;
                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载打印坐标时出现错误 ！</strong>');
                  }
              });
          });
          function CreateOneFormPage() {
              LODOP = getLodop();
              LODOP.PRINT_INIT("存折打印");
              LODOP.SET_PRINT_STYLE("FontSize", 18);
              LODOP.SET_PRINT_STYLE("Bold", 1);
              LODOP.ADD_PRINT_TEXT(0, 0, 0, 0, "打印页面部分内容");
          
              LODOP.ADD_PRINT_HTM(p_ltop, p_lleft, p_lwidth, p_lheight, document.getElementById("divPrint").innerHTML);

          };



          function PrintCunZhe() {

              $.ajax({
                  url: '/Ashx/storage.ashx?type=PrintDep_OperateLog&BusinessNO=' + $('input[name=BusinessNO]').val() + '&AccountNumber=' + $('#D_AccountNumber').html(),
                  type: 'post',
                  data: '',
                  dataType: 'text',
                  success: function (r) {
                      $('#divPrint').html('');
                      $('#divPrint').append(r);
                      CreateOneFormPage();
                      LODOP.PREVIEW(); //打印存折
                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载打印坐标时出现错误 ！</strong>');
                  }
              });
          }
      </script>
</head>
<body>
    <div id="divPrint" style="display:none">

    </div>
    <form id="form1" runat="server">
    <div class="pageHead">
        <b>储户存粮</b><span id="spanHelp" style="cursor: pointer">帮助</span>
    </div>
    <div id="divHelp" class="pageHelp" style="border:1px solid #333; border-radius:5px; display:none; ">
<span>提示1：请认真填写储户的存储产品信息，储户类型、存期信息；储户类型确定储户存储的是否是定期产品，不同的存期类型也会有不同的利息计算方式！</span><br />
<span>提示2：如果保存后，发现有错误，可以使用 修改错误存粮 修改数据。</span><br />

</div>
<div id="storageQuery">

</div>
    <div style="margin: 20px 0px;">
        <div id="Query">
            <span>储户账号:</span>
            <input type="text" id="QAccountNumber" style="font-size:16px; font-weight:bolder;" runat="server" />
                       &nbsp; <span>密码:</span>
            <input type="password" id="QPassword" style="font-size:12px;  width:100px;" runat="server" />
          
            <asp:ImageButton ID="ImageButton1" ImageUrl="~/images/seach_brown.png" 
                runat="server" onclick="ImageButton1_Click" />
        </div>
          <div id="depositorInfo"  runat="server" style="display:none;">
            <table class="tabData"  style="margin:20px 0px;">
                <tr >
                    <td colspan="6" style="border-bottom:1px solid #aaa; height:25px; text-align:center">
                        <span style="font-size: 16px; font-weight: bolder; color:Green">储户基本信息</span>
                    </td>
                </tr>
                <tr>
                    <th align="center" style="width:100px; height:30px;">
                        储户账号
                    </th>
                    <th align="center" style="width:100px;">
                        储户姓名
                    </th>
                     <th align="center" style="width:100px;">
                        移动电话
                    </th>
                      <th align="center" style="width:100px;">
                        当前状态
                    </th>
                      <th align="center" style="width:150px;">
                        身份证号
                    </th>
                     <th align="center" style="width:200px;">
                        储户地址
                    </th>
                   
                </tr>
                   <tr>
                  
                    <td style="height:30px;">
                        <span style="font-weight:bolder; color:Blue;" id="D_AccountNumber"   runat="server"></span>
                    </td>
                    
                    <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_strName" runat="server"></span>
                    </td>
                    <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_PhoneNo" runat="server"></span>
                    </td>
                     <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_numState" runat="server"></span>
                    </td>
                      <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_IDCard" runat="server"></span>
                    </td>
                    <td>
                        <span style="font-weight:bolder; color:Blue;" id="D_strAddress" runat="server"></span>
                    </td>
                </tr>
            </table>
        </div>
        <div id="StorageList" runat="server" style="display:none">
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table class="tabData" >
                    <tr class="tr_head">
                        <th style="width: 100px; height:20px; text-align: center;">
                            存贷产品
                        </th>
                        <th style="width: 80px; text-align: center;">
                            结存数量
                        </th>
                        <th style="width: 100px; text-align: center;">
                            存入时间
                        </th>
                        <th style="width: 80px; text-align: center;">
                            存入价
                        </th>
                        <th style="width: 80px; text-align: center;">
                            存期
                        </th>
                        <th style="width: 80px; text-align: center;">
                            天数
                        </th>
                        <th style="width: 80px; text-align: center;">
                            活期利率
                        </th>
                        <th style="width: 100px; text-align: center;">
                            利息
                        </th>
                        <th style="width: 160px; text-align: center;">
                            结算类型
                        </th>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr style='background-color: <%#(Container.ItemIndex%2==0)?"#FFFFF;":"#fcf3f4"%>'
                    onmouseover="change_colorOver(this)" onmouseout="change_colorOut(this)">
                    <td style="height:25px;">
                        <%#Eval("VarietyID")%>
                    </td>
                    <td>
                        <%#Eval("StorageNumber")%>
                    </td>
                    <td>
                        <%#Eval("StorageDate")%>
                    </td>
                    <td>
                        <%#Eval("Price_ShiChang")%>
                    </td>
                    <td>
                        <%#Eval("TimeID")%>
                    </td>
                    <td>
                        <%#Web.common.GetDay(Eval("StorageDate"))%>
                    </td>
                    <td>
                        <%#Eval("CurrentRate")%>
                    </td>
                    <td>
                        <%#Web.common.GetLiXi(Eval("ID"))%>
                    </td>
                    <td>
                       <a href="/User/Exchange/ExchangeGoods.aspx?Dep_SID=<%#Eval("ID") %>">兑换</a>&nbsp;
                    <a href="/User/Exchange/StoreToSell.aspx?Dep_SID=<%#Eval("ID") %>">存转销</a>&nbsp;
                       <a href="/User/Storage/StorageRenew.aspx?Dep_SID=<%#Eval("ID") %>">结息</a>
                       
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
            <tr>
            <td colspan="2">
            <span style="font-weight:bolder">折合现金合计:</span>
            </td>
            <td colspan="6" style="text-align:center">
            <span id="spanTotal" runat="server" style="color:Red; font-size:16px">￥<%=Web.common.numTotol%></span>
          
            </td>
            </tr>
                <!--底部模板-->
                </table>
                <!--表格结束部分-->
            </FooterTemplate>
        </asp:Repeater>
        </div>

    </div>
    <div id="divfrm" class="pageEidtInner" runat="server" style="border-radius:20px; display:none;" >
       
        
        <div>
            <table>
            <tr><td colspan="2" style=" border-bottom:1px solid #aaa;"><span style="font-size:16px; font-weight:bolder; color:Blue; margin-left:50px;">存粮信息</span></td></tr>
                <tr>
                    <td align="right" style="width: 100px;">
                     <span>存储产品:</span> 
                    </td>
                    <td>
                       <select name="VarietyID"></select>                     
                    </td>
                </tr>
              <tr>
                   <td align="right"><span>储户类型:</span>
                    </td>
                    <td>
                       <select name="TypeID" style="width:100px;" ></select> 
                        存期: <select name="TimeID" style="width:100px;"></select> 
                      </td>
                </tr>
                  <tr>
                   <td align="right"><span>存入价格:</span>
                    </td>
                    <td>      
                       <input type="text" style="width:100px;background-color:#ddd;" name="Price_ShiChang"  readonly="readonly"  />
                       <span id="spanPrice_ShiChang"></span>
                    </td>
                </tr>
              
                <tr>
                   <td align="right"><span>保管费率:</span>
                    </td>
                    <td>
                        <input type="text" name="StorageFee"  readonly="readonly" style="background-color:#ddd; width:100px;" />%
                      
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <span>存入日期:</span>
                    </td>
                    <td>
                        <input type="text"   name="StorageDate"  readonly="readonly" style="background-color:#ddd;"/>
                    </td>
                </tr>
               <tr>
                    <td align="right"> <span>磅单编号:</span>
                    </td>
                    <td>
                       <input name="WeighNO" type="text"  />
                    </td>
                </tr>
               <tr>
                   <td align="right"> <span>存储数量:</span>
                    </td>
                    <td>
                          <input name="StorageNumber" type="text" onblur="FunCheckNumber()" style="width: 100px; color:Red;"  value="0" />
                         <span id="spanStorageNumber"></span>
                    </td>
                </tr>
             

                   <tr>
                    <td>
                    </td>
                    <td>
                        <input type="button"  id="btnAdd" value="保存数据" onclick="InitBusinessNO();" />&nbsp;&nbsp;
      
                              <input type="button" id="btnCunZhe"  value="打印存折" disabled="disabled" onclick="PrintCunZhe()" />
                        
                    </td>
                </tr>
                <tr><td colspan="2"><div id="divMsg" style="color:Red; font-size:16px;"></div></td></tr>
            </table>
        </div>
    </div>
    <div  style="display:none;">
    <%--业务编号--%>
      <input type="text"  name="BusinessNO" value="" />
   
      <%--存储于利率账号--%>
    <input type="text" name="StorageRateID" value="" />

    </div>
    </form>
    
    <%--定义编号--%>
    <input type="hidden" id="WBID" value="" />
    <%--定义背景色的隐藏域--%>
    <input type="hidden" id="colorName" value="" />
</body>
</html>
